package com.fengmi.security1;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * @Author 123
 * @Date 2022/2/9 21:10
 * @Version 1.0
 */

//springsecurity配置类
@EnableWebSecurity
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true,securedEnabled = true,jsr250Enabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {




    //静态资源放行
    @Override
    public void configure(WebSecurity web) throws Exception {

        web.ignoring().antMatchers("/swagger-ui.html/**","/css/**","/images/**","/plugins/**","/webjars/**",
                "/swagger-resources/**","/v2/**");
    }


    //配置系统资源的访问规则
    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.authorizeRequests().antMatchers("/u/login","/u/check")
                .permitAll()
                .anyRequest()
                .authenticated();

        //自定义过滤器生效
        http.addFilter(new CustomerBasicAuthenticationFilter(authenticationManagerBean()));


        http.csrf().disable();//禁用csrf过滤器


        http.cors(); //跨域解决


    }
}
